<template>
	<view class="authentication">
		<u-navbar
            leftText=""
            :safeAreaInsetTop="true"
        >
            <view
                class="u-nav-slot"
                slot="left"
            >
                <u-icon
                    name="arrow-left"
                    size="20"
					margin-top="20rpx"
					@click="back"
                ></u-icon>
            </view>
        </u-navbar>
		
		<view class="innerbox">
			<view class="authenticationtext">
				身份验证
			</view>
			
			<view class="codebox">
				<image class="codeimg" src="http://sssx.nanjingyunpeng.cn/uploads/tupian/image/shenfen.png"></image>
				<view class="codeinput">
					 <u--input
					   v-model="value"
					    placeholder="请输入身份证号"
					    border="bottom"
						maxlength='18'
					    clearable
						   @change="hadleinput"
					  ></u--input>
				</view>
			</view>
			
			<view class="submit"@click="submit">
				确认提交
			</view>
			
		</view>
		
			<u-popup :show="show" mode="center" :round="10" closeable="true" @close="close" @open="open">
		            <view class="wrongbox">
						<image class="wrongimg" src="http://sssx.nanjingyunpeng.cn/uploads/tupian/image/wrong.png"></image>
						<view class="wrongtitle">
							验证失败
						</view>
						<view class="wrongtext">
							您当前暂无权限使用哦
						</view>
		            </view>
				</u-popup>
	</view>
</template>

<script>
	import{authentication,usermessage} from "@/api/api.js"
	export default{
		data(){
			return{
				show:false,
				value:"",
			}
		},
		onLoad() {
			this.usermessages()
		},
		methods:{
			hadleinput(e){
				this.value = e
				// console.log("eee",e)
			},
			async usermessages(){
				let res = await usermessage()
				if(res.code ==1){
					console.log("用户信息",res)
					if(res.data.is_card ==1){
						uni.navigateTo({
							url:"/pages/selectIdentity/index"
						})
					}
				}
			},
		async submit(){
				console.log("身份证号",this.value)
				if(this.value == ""){
					uni.showToast({
						title: '请先输入身份证号！',
						icon: 'none',
						duration: 1000
					})
				}else{
					this.authentications()
				}
			},
			async authentications(){
				let res = await authentication({
					id_card:this.value
				})
				if(res.code == 1){
					uni.setStorageSync("token", res.data.token.access_token)
					console.log("身份证验证",res)
					uni.navigateTo({
						url:"/pages/selectIdentity/index"
					})
				}else{
					this.show = true
					this.value=''
				}
			},
			close(){
				this.show = false
			},
			open(){
				
			},
			back(){
				uni.navigateBack({
					delta: 1
				});
			}
		}
	}
</script>

<style scoped lang="scss">
	.authentication{
		.innerbox{
			width: 622rpx;
			height: 548rpx;
			margin: 0 auto;
			margin-top: 216rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: space-between;
			.authenticationtext{
				width: 176rpx;
				height: 62rpx;
				font-size: 44rpx;
				font-family: PingFang SC-Bold, PingFang SC;
				font-weight: bold;
				color: #333333;
				line-height: 52rpx;
			}
			.codebox{
				width: 622rpx;
				display: flex;
				align-items: center;
				.codeimg{
					width: 80rpx;
					height: 80rpx;
					margin-right: 30rpx;
				}
				.codeinput{
					flex: 1;
				}
			}
			.submit{
				width: 622rpx;
				height: 88rpx;
				background: #4A9CFF;
				border-radius: 200rpx 200rpx 200rpx 200rpx;
				opacity: 1;
				font-size: 32rpx;
				font-family: PingFang SC-Bold, PingFang SC;
				font-weight: bold;
				color: #FFFFFF;
				line-height: 88rpx;
				text-align: center;
			}
		}
		.wrongbox{
			width: 610rpx;
			height: 288rpx;
			padding: 50rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: space-between;
			box-sizing: border-box;
			.wrongimg{
				width: 64rpx;
				height: 64rpx;
			}
			.wrongtitle{
				font-size: 32rpx;
				font-family: PingFang SC-Bold, PingFang SC;
				font-weight: bold;
				color: #333333;
				line-height: 38rpx;
			}
			.wrongtext{
				font-size: 28rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #999999;
				line-height: 33rpx;
			}
		}
	}
</style>